home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / ANTENNA / YAGIU112 / FITNESS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-25  |  1.8 KB  |  49 lines

  1. /* This function solves all the simultaneous equatons and returns a
  2. double which increases with a better antenna. */
  3.  
  4. #include <stdio.h>
  5. #include <errno.h>
  6.  
  7. #include "yagi.h"
  8.  
  9. extern int errno;
  10. extern struct performance_data max, weight;
  11.  
  12. double get_genetic_algorithm_fitness(struct flags flag, double frequency, int driven, int parasitic, double **driven_data, double **parasitic_data, double *v, double **z, double *pin, struct FCOMPLEX *voltage, struct FCOMPLEX *current, struct FCOMPLEX *input_impedance, struct element_data *coordinates, double **A, double  *b, int *indx, struct performance_data *data2) 
  13. {
  14.     double result, new_gain, new_fb_ratio, E_fwd, E_back, H_fwd,
  15.     H_back; 
  16.     double vswr, mag, phase;
  17.     int elements;
  18.     struct performance_data data,start;
  19.     start.gain=0.0;
  20.     elements=driven+parasitic;
  21.     solve_equations(frequency, driven, parasitic, driven_data, parasitic_data, v, z, pin, voltage, current, input_impedance, coordinates, A, b, indx);
  22.     /* compute gain at theta=90, phi=0 (forward direction) */
  23.     gain(90,0,*pin,1.0,coordinates,current,elements,&E_fwd,&H_fwd,frequency,frequency);
  24.     /* now compute gain in the reverse direction */
  25.     gain(270,0,*pin,1.0,coordinates,current,elements,&E_back,&H_back,frequency,frequency);
  26.     data.gain=E_fwd;            /* in dB */
  27.     data.fb=E_fwd-E_back; /* gains are already in dB, so subtract */
  28.     data.r=input_impedance->r;
  29.     data.x=input_impedance->i;
  30.     reflection_coefficient(*input_impedance, &mag, &phase);
  31.     data.swr=calculate_vswr(mag);
  32.     if((flag.gflg&SIDE_LOBE_LEVEL)==SIDE_LOBE_LEVEL)
  33.         data.sidelobe=find_max_sidelobe_fast(E_fwd, *pin,coordinates, \
  34.         current,elements,frequency,frequency);
  35.     else
  36.         data.sidelobe=0.0;
  37.     *data2=data;
  38.     result=performance(flag, data, max, weight, start);
  39.  
  40. #ifdef DEBUG
  41.     if(errno)
  42.     {
  43.         fprintf(stderr,"Errno =%d in fitness.c\n", errno);
  44.         exit(1);
  45.     }
  46. #endif
  47.     return (result);
  48. }
  49.